<?php
/**
 * Cms_Model_Acl_Cms
 *
 * Implements the Access Control List for the Cms Module
 *
 * @category   Cms_Model
 * @package    Cms_Model_Acl
 */

class Cms_Model_Acl_Cms extends Zend_Acl
{


public function __construct($groupId)
{
    $resourceService = new Cms_Service_Resource();

    $adminGroup = new Cms_Model_Administrator();
    $adminGroup = $adminGroup->getAdministratorGroupById($groupId);

    $accessPermission = $adminGroup->accessPermission;
    $modifyPermission = $adminGroup->modifyPermission;

    //add resources
    $resources = $resourceService->getAccessPermissions();
    foreach ($resources as $resource) {
        $this->add(new Zend_Acl_Resource($resource));
    }

    $this->addRole(new Zend_Acl_Role($groupId));

        if(isset($accessPermission) && is_array($accessPermission)){
            foreach($accessPermission as $accessResource){ 
                if(!empty($accessResource)){
                   $this->allow($groupId, $accessResource,'access');
                }
            }
        }
        
        if(isset($modifyPermission) && is_array($modifyPermission)){
            foreach($modifyPermission as $modifyResource){
                 if(!empty($accessResource)){
                   $this->allow($groupId, $modifyResource,array('insert','update','delete'));
                 }
            }
        }

 }

}